package basicservicelogic

import (
	"context"
	"property_service/dao/model"
	"property_service/dao/query"
	"property_service/internal/svc"
	"property_service/property_service"
	"property_service/utils/result"

	"github.com/zeromicro/go-zero/core/logx"
)

type SupplierLevelAdditionEditLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSupplierLevelAdditionEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SupplierLevelAdditionEditLogic {
	return &SupplierLevelAdditionEditLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// SupplierLevelAdditionEdit 更新供应商级别信息
func (l *SupplierLevelAdditionEditLogic) SupplierLevelAdditionEdit(in *property_service.SupplierLevelAddition) (*property_service.Response, error) {
	// 获取供应商级别信息模型的查询构造器
	m := query.Use(l.svcCtx.Gorm).SupplierLevelAddition
	// 构建查询条件：根据ID查询
	do := m.WithContext(l.ctx).Where(m.ID.Eq(in.ID))
	// 执行更新操作，仅更新指定字段，不包含ID、TenantID、UpdatedAt、CreatedAt
	if _, err := do.UpdateColumns(&model.SupplierLevelAddition{
		SupplierLevelName: in.SupplierLevelName, // 供应商级别名称
		SupplierPhone:     in.SupplierPhone,     //供应商人
		SupplierPerson:    in.SupplierPerson,    //供应商电话
		Address:           in.Address,           //供应商地址
		PronunciationCode: in.PronunciationCode, // 拼音简码
		Remark:            in.Remark,            // 备注
		UpdatedAtuser:     in.UpdatedAtuser,     // 更新用户
	}); err != nil {
		// 如果更新失败，返回错误响应
		return result.Err(err).Ed()
	}
	// 更新成功，返回成功响应
	return result.Suc().EditEd()
}
